package com.example.academic_affairs_system.config;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if (request.getSession().getAttribute("adminName") == null) {
            /**
             * 开发阶段，先注释😎
             */
            request.setAttribute("F", "please login.");
            request.getRequestDispatcher("/login.html").forward(request,response);
            return false;
        }

        return true;
    }
}
